package com.sxt.bus.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.sxt.bus.BUSConstast.BUSConstast;
import com.sxt.bus.service.CustomerService;
import com.sxt.bus.vo.CustomerVo;
import com.sxt.sys.SYSConstast.SYSConstast;
import com.sxt.sys.utils.ResultObj;
import com.sxt.sys.vo.LoginInforVo;
import com.sxt.bus.utils.DataGridView;

@RestController
@RequestMapping("customer")
public class CustomerController {
	
	
	@Autowired
	private CustomerService customerService;
	

	
	@RequestMapping("loadAllCustomer")
	public DataGridView loadAllCustomer(CustomerVo customerVo) {
		
		return customerService.queryAllCustomer(customerVo);
	}
	
	@RequestMapping("deleteCustomer")
	public ResultObj deleteCustomer(CustomerVo customerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = customerService.deleteCustomer(customerVo.getId());
			code = info;
			msg = info > 0 ?SYSConstast.DELETE_LOGININFOR_TRUE:SYSConstast.DELETE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = SYSConstast.DELETE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	@RequestMapping("updateCustomer")
	public ResultObj updateCustomer(CustomerVo customerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = customerService.updateCustomer(customerVo);
			code = info;
			msg = info > 0 ?BUSConstast.UPDATE_LOGININFOR_TRUE:BUSConstast.UPDATE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = BUSConstast.UPDATE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	
	@RequestMapping("addCustomer")
	public ResultObj addCustomer(CustomerVo customerVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = customerService.addCustomer(customerVo);
			code = info;
			msg = info > 0 ?BUSConstast.ADD_LOGININFOR_TRUE:BUSConstast.ADD_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = BUSConstast.ADD_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
}
